package com.sims.action;

import com.opensymphony.xwork2.ActionSupport;
import com.sims.service.IUserService;
import com.sims.service.impl.UserServiceImp;

public class LoginAction extends ActionSupport {
	private String userAccount;
	private String userPassword;

	public String getUserAccount() {
		return userAccount;
	}

	public void setUserAccount(String userAccount) {
		this.userAccount = userAccount;
	}

	public String getUserPassword() {
		return userPassword;
	}

	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}

	// 改变语言方法
	public String changeLanguage() {
		return this.INPUT;
	}

	// 输入验证
	public void validateLoginCheck() {
		super.validate();
		if (userAccount == null || userAccount.trim().length() < 1) {
			this.addFieldError("userAccount",
					this.getText("login.requireAccount"));
			System.out.println("账号不能为空");
		}
		if (userPassword == null || userPassword.trim().length() < 1) {
			this.addFieldError("userPassword",
					this.getText("login.requirePassword"));
			System.out.println("密码不能为空");
		}
	}
	// struts2 的action方法
	public String loginCheck() throws Exception {
		boolean validate = false;
		IUserService userVice = new UserServiceImp();
		validate = userVice.validateLogin(userAccount, userPassword);

		if (validate) {
			return "success";
		} else {
			return "error";
		}
	}

}
